package it.mozzicato.apkwizard;

import java.io.*;
import java.util.logging.*;

import javax.swing.*;
import javax.swing.text.*;

// Creato il 17/mag/2011

/**
 * @author Roberto Mozzicato
 *
 */
public class ApkToolLogHandler extends StreamHandler {
	private JLabel label;
	private JTextComponent textArea;
	
	public ApkToolLogHandler() {
		OutputStream voidStream = new OutputStream() {
			@Override
			public void write(int b) throws IOException {}
		};
		
		Formatter formatter = new Formatter() {
			
			@Override
			public String format(LogRecord record) {
				if(label != null && label.isShowing() && label.isShowing() && record.getLevel().intValue() >= Level.INFO.intValue())
					label.setText(record.getMessage());
				
				ApkWizard.appendLog(textArea, record.getMessage(), record.getLevel());
					
				return "";
			}
		};
		
		setOutputStream(voidStream);
		setFormatter(formatter);
	}

	public JLabel getLabel() {
		return label;
	}

	public void setLabel(JLabel label) {
		this.label = label;
	}
	
	public void setTextArea(JTextComponent textArea) {
		this.textArea=textArea;
	}

	public JTextComponent getTextArea() {
		return textArea;
	}
}
